package controller

import (
	"GO/common"
	"GO/model"
	"net/http"

	"github.com/gin-gonic/gin"
)

func Get_Hum(c *gin.Context) {
	var result []model.Hum_Arr
	db := common.GetDB()
	//执行sql语句，返回小时数和对应的温度
	if err := db.Raw("SELECT hum,HOUR(time) AS hour FROM (SELECT id,hum,time FROM enveronment_information  ORDER BY id DESC LIMIT 24) AS tbl ORDER BY id ASC").Scan(&result); err.Error != nil {
		c.JSON(http.StatusOK, gin.H{
			"status": 400,
			"err":    err,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"status": 200,
		"Data":   result,
	})
}
